<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="所属用户:" prop="user_id.value">
                            <SelectPage v-model="queryParams.user_id.value" placeholder="请选择所属用户"
                                        :url="'/admin/user/selectPage'" show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12">
                        <el-form-item label="创建日期:" prop="create_time.value">
                            <el-date-picker
                                v-model="queryParams.create_time.value"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                          </el-form-item>
                    </el-col>

                    <el-col :md="6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>


            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5" v-if="false">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="180">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button>
                            <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button>
                        </template>
                    </el-table-column>
                </template>
            </qa-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? ( findFormData[pk] ? '编辑' : '添加' ) : '详情'" :visible="editOpen" :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData" :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>
        <el-dialog title="评论列表" :visible.sync="commentVisible" width="80%" destroy-on-close append-to-body class="dialog-no-pd">
            <div style="height: 70vh;overflow-y: auto">
                <postCommentList :postId="currentRow.id"></postCommentList>
            </div>
        </el-dialog>
        <el-dialog :title="pvObj.type === 1 ? '查看列表' : '分享列表'" :visible.sync="pvObj.visible"
                   class="dialog-no-pd"
                   width="60%" destroy-on-close append-to-body>
            <div style="height: 70vh;overflow-y: auto" v-if="pvObj.visible">
                <pvList :queryObj="pvObj"></pvList>
            </div>
        </el-dialog>
        <el-dialog title="点赞列表" :visible.sync="zanObj.visible"
                   class="dialog-no-pd"
                   width="60%" destroy-on-close append-to-body>
            <div style="height: 70vh;overflow-y: auto" v-if="zanObj.visible">
                <zanList :queryObj="zanObj"></zanList>
            </div>
        </el-dialog>
        <el-dialog title="收藏列表" :visible.sync="collectObj.visible"
                   class="dialog-no-pd"
                   width="60%" destroy-on-close append-to-body>
            <div style="height: 70vh;overflow-y: auto" v-if="collectObj.visible">
                <collectList :queryObj="collectObj"></collectList>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
import postCommentList from '../post_comment/index'
import pvList from '../post_pv/index'
import zanList from '../post_zan/index'
import collectList from '../post_collect/index'

export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm, postCommentList, pvList, zanList, collectList },
    data() {
        return {
            // table结构
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'id',
                },
                {
                    visible: true,
                    label: '所属用户',
                    prop: 'myUser.nickname',
                },
                {
                    visible: true,
                    label: '图片',
                    prop: 'pic_urls',
                    component:'QuickAdminImage',
                },
                {
                    visible: true,
                    label: '查看数',
                    prop: 'view_num',
                    formatter: (prop, row)=> {
                        return `<a href="javascript:;" class="cBlue">${row.view_num}</a>`
                    },
                    click: (prop, row)=> {
                        this.pvObj.visible = true
                        this.pvObj.post_id = row.id;
                        this.pvObj.type = 1
                    }
                },
                {
                    visible: true,
                    label: '分享数',
                    prop: 'share_num',
                    formatter: (prop, row)=> {
                        return `<a href="javascript:;" class="cBlue">${row.share_num}</a>`
                    },
                    click: (prop, row)=> {
                        this.pvObj.visible = true
                        this.pvObj.post_id = row.id;
                        this.pvObj.type = 2
                    }
                },
                {
                    visible: true,
                    label: '点赞数',
                    prop: 'zan_num',
                    formatter: (prop, row)=> {
                        return `<a href="javascript:;" class="cBlue">${row.zan_num}</a>`
                    },
                    click: (prop, row)=> {
                        this.zanObj.visible = true
                        this.zanObj.post_id = row.id;
                        this.zanObj.data_type = row.data_type
                    }
                },
                {
                    visible: true,
                    label: '收藏数',
                    prop: 'collect_num',
                    formatter: (prop, row)=> {
                        return `<a href="javascript:;" class="cBlue">${row.collect_num}</a>`
                    },
                    click: (prop, row)=> {
                        this.collectObj.visible = true
                        this.collectObj.post_id = row.id;
                        this.collectObj.data_type = row.data_type
                    }
                },
                {
                    visible: true,
                    label: '评论数',
                    prop: 'comment_num',
                    formatter: (prop, row)=> {
                        return `<a href="javascript:;" class="cBlue">${row.comment_num}</a>`
                    },
                    click: (prop, row)=> {
                        this.currentRow = row
                        this.commentVisible = true
                    }
                },
                {
                    visible: true,
                    label: '创建日期',
                    prop: 'create_time',
                },
                {
                    visible: true,
                    label: '排序',
                    prop: 'sortweight',
                },
                {
                    visible: true,
                    label: '话题',
                    prop: 'tag_datas'
                },
                {
                    visible: true,
                    label: '宝宝周数',
                    prop: 'baby_week',
                },
            ],
            // 接口地址
            api: {
                index: `/admin/sq.post/index`,
                find: `/admin/sq.post/find`,
                add: `/admin/sq.post/add`,
                edit: `/admin/sq.post/edit`,
                delete: `/admin/sq.post/delete`,
                export: `/admin/sq.post/export`,
                status: `/admin/sq.post/status`
            },
            editFormParams: {},
            // 搜索表单是否展开
            searchExpand: false,
            // 查询参数
            queryParams: {
                user_id: { value:undefined, op: '='},
                data_type: { value:undefined, op: '='},
                status: { value:undefined, op: '='},
                create_time: { value:[], op: 'range'},
            },
            data_type:[
               { label: "图文", value: 1 },
               { label: "视频", value: 2 },
            ],
            currentRow: {},
            commentVisible: false,
            pvObj: {
                visible: false,
                post_id: '',
                type: 1
            },
            zanObj: {
                visible: false,
                post_id: '',
                data_type: 1
            },
            collectObj: {
                visible: false,
                post_id: '',
                data_type: 1
            }
        }
    }
}
</script>
